//
//  KWTMGRNSettingEleCell.m
//  RuiHeApp
//
//  Created by Yan Chen on 2024/7/29.
//

#import "KWTMGRNSettingEleCell.h"
@interface KWTMGRNSettingEleCell()
@property (nonatomic, strong) QMUILabel *titleLab;

@property (nonatomic, strong) QMUITextField *textField;
@end
@implementation KWTMGRNSettingEleCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}


-(void)setModel:(KWTMGRNSettingModel *)model
{
    _model = model;
    self.titleLab.text = model.rowTitle.rh_localized;
}

-(void)setupUI
{
    kWeakSelf;
    self.contentView.backgroundColor = kCOLOR_HEX(@"#F0F5FF");
    UIView *bgView = [[UIView alloc]init];
    bgView.backgroundColor = UIColor.whiteColor;
    [self.contentView addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsMake(0, 15, 0, 15));
    }];
    
    QMUILabel *titleLab = [QMUILabel labelWithText:@"" font:kSYSTEMFONT(14) textColor:kCOLOR_HEX_A(@"#171A1D", 0.6)];
    [bgView addSubview:titleLab];
    self.titleLab = titleLab;
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(10);
        make.left.mas_offset(15);
    }];
    
    _textField = [[QMUITextField alloc]init];
    _textField.textInsets = UIEdgeInsetsMake(0, 10, 0, 15);
    _textField.layer.borderColor = kCOLOR_HEX_A(@"#7E868E", 0.3).CGColor;
    _textField.layer.borderWidth = 1;
    _textField.layer.cornerRadius = 5;
    _textField.layer.masksToBounds = YES;
    _textField.font = kSYSTEMFONT(14);
    _textField.placeholder = @"请输入".rh_localized;
    _textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
    [bgView addSubview:_textField];
    [_textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLab);
        make.height.offset(35);
        make.top.equalTo(titleLab.mas_bottom).offset(10);
        make.right.mas_offset(-15);
        make.bottom.mas_offset(-5);
    }];
    
    [[RACSignal merge:@[self.textField.rac_textSignal, RACObserve(self.textField, text)]] subscribeNext:^(NSString* text){
         
          weakSelf.model.content = [NSDecimalNumber decimalStringWithDouble:[text doubleValue]];
    }];
}

@end
